<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="HTML_TEXT_FIELD_MAX_LENGTH" />
<atleap:constants className="com.blandware.atleap.model.core.ContentField" scope="page" var="LINE_TYPE" />
<atleap:constants className="com.blandware.atleap.model.core.ContentField" scope="page" var="MULTILINE_TYPE" />
<atleap:constants className="com.blandware.atleap.model.core.ContentField" scope="page" var="HTML_TYPE" />
<atleap:constants className="org.apache.struts.Globals" var="LOCALE_KEY" scope="page" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="OWNER_INFO_KEY" scope="page" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="CONTENT_FIELD_KEY" scope="page" />

<c:set var="contentField" value="${sessionScope[pageScope.CONTENT_FIELD_KEY]}" />
<c:choose>
    <c:when test="${!empty contentField}">
        <c:set var="fieldIdentifier" value="${contentField.identifier}" />
        <c:set var="fieldType" value="${contentField.type}" />
    </c:when>
    <c:when test="${!empty contentFieldValueForm.identifier}">
        <c:set var="fieldIdentifier" value="${contentFieldValueForm.identifier}" />
        <c:set var="fieldType" value="${contentFieldValueForm.fieldType}" />
    </c:when>
    <c:otherwise>
        <c:set var="fieldIdentifier" value="${contentFieldValueForm.indexedIdentifier}" />
        <c:set var="fieldType" value="${contentFieldValueForm.fieldType}" />
    </c:otherwise>
</c:choose>

<atleap:content identifier="information" ignore="true" />
<atleap:messages />
<atleap:form action="core/contentFieldValue/createOrUpdate" method="POST" validateOnSubmit="false">
    <c:if test="${!empty param.locale}">
        <html:hidden property="locale" value="${param.locale}" />
    </c:if>
	<table cellpadding="0" cellspacing="0" border="0" class="modificationTable">
		<tr>
			<th><atleap:message key="core.contentFieldValue.form.contentFieldOwnerInfo" /></th>
			<td>${sessionScope[pageScope.OWNER_INFO_KEY]}</td>
        </tr>
        <tr>
            <th><atleap:message key="core.contentFieldValue.form.contentFieldIdentifier" /></th>
            <td><c:out value="${fieldIdentifier}" escapeXml="true" /></td>
        </tr>
    </table>
	<atleap:iterator items="${contentFieldValueForm.localeMap}" var="entry">
		<c:set var="key" value="${entry.key}" />
		<c:set var="contentLocale" value="${entry.value}" />
        <table cellpadding="0" cellspacing="0" border="0" class="modificationTable">
            <tr>
                <th>
                    <div class="readOnlyField">
                        <atleap:message key="core.contentFieldValue.form.language" />
                    </div>
                </th>
                <td>
                    <div class="readOnlyField">
						<atleap:fieldValue valueMap="${contentLocale.title}" var="languageTitle" />
						<c:if test="${empty languageTitle}">
							<c:set var="languageTitle" value="${contentLocale.identifier}" />
						</c:if>
						${languageTitle}
                    </div>
                </td>
            </tr>
            <c:choose>
                <c:when test="${fieldType == pageScope.LINE_TYPE}">
                    <tr>
                        <th>
                            <div class="readOnlyField">
                                <atleap:label property="value(${key})" key="core.contentFieldValue.form.value" colon="false" helpTip="false" />
                            </div>
                        </th>
                        <td>
                            <html:text styleClass="text" property="value(${key})" maxlength="${pageScope.HTML_TEXT_FIELD_MAX_LENGTH}" />
                        </td>
                    </tr>
                 </table>
                 <br />
                </c:when>
                <c:when test="${fieldType == pageScope.MULTILINE_TYPE}">
                    <tr>
                        <th>
                            <div class="readOnlyField">
                                <atleap:label property="value(${key})" key="core.contentFieldValue.form.value" colon="false" helpTip="false" />
                            </div>
                        </th>
                        <td>
                            <html:textarea property="value(${key})" style="width: 350px;" />
                        </td>
                    </tr>
                </table>
                <br />
                </c:when>
                <c:when test="${fieldType == pageScope.HTML_TYPE}">
                    </table>
                    <br />
                    <div class="readOnlyField">
                        <atleap:label property="value(${key})" key="core.contentFieldValue.form.value" colon="false" helpTip="false" />
                    </div>
                    <atleap:base var="baseHref" />
                    <atleap:contentEditor id="value(${key})" basePath="${ctxPath}/FCKeditor/" width="100%" height="400px"
                            defaultLanguage="${sessionScope[pageScope.LOCALE_KEY].language}" baseHref="${baseHref}"
                            editorAreaLanguage="${key}">
                        ${contentFieldValueForm.valueMap[key]}
                    </atleap:contentEditor>
                    <br />  
                </c:when>
            </c:choose>
            <html:hidden property="id(${key})" />
            <html:hidden property="version(${key})" />
    </atleap:iterator>
    <html:hidden property="contentFieldId"/>
    <html:hidden property="ownerId"/>
    <html:hidden property="identifier"/>
    <html:hidden property="indexedIdentifier"/>
    <html:hidden property="currentIndex"/>
    <html:hidden property="fieldType"/>
    <html:hidden property="definition"/>
    <atleap:submit styleClass="button"><atleap:message key="core.commons.buttons.update" /></atleap:submit>
    <atleap:cancel styleClass="button"><atleap:message key="core.commons.buttons.cancel" /></atleap:cancel>
    <br />
</atleap:form>
